#include "Student.h"
#include "Klass.h"
#include <iostream>
using namespace std;

Student::Student(string id, string name, size_t age, Klass &klass) : Person(id, name, age), klass(&klass)
{
    this->klass->AppendMember(*this);
}

string Student::Introduce()
{

    string result = Person::Introduce() + " I am a Student.";

    string normalStudentString = " I am at Class " + *(this->klass) + ".";
    if(this->klass->HasLeader(*this)){
        result += " I am a Leader of Class " + *(this->klass) +".";
    } else {
        result += normalStudentString;
    }
    return result;
}

string Student::WithName(std::function<std::string(std::string)> handler) const
{
    return handler(this->name);
}

bool Student::IsIn(const Klass &klass) const 
{
    return this->klass != nullptr && (klass == *this->klass);
}

bool Student::operator==(const Student &person)
{
    return Person::IsEqual(person);
}

void Student::ReAssignKlass(Klass &klass)
{
    if (!this->IsIn(klass)) {
        klass.AppendMember(*this);
        this->klass = &klass;
    }
}